package ink.lovejinhu.leetcode;

import ink.lovejinhu.common.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: jin
 * @Date: 2021/9/7 19:44
 * @Version: V1.0
 * @Slogan: Great people are not born great, but show their greatness in the process of growing up
 **/
public class Solution_0872 {
    /**
     * 叶子相同的树
     * 叶子是出度为0的节点
     *
     * @param root1
     * @param root2
     * @return
     */
    public boolean leafSimilar(TreeNode root1, TreeNode root2) {
        ArrayList<Integer> v0 = new ArrayList<>();
        ArrayList<Integer> v1 = new ArrayList<>();
        dfs(root1, v0);
        dfs(root2, v1);
        System.out.println(v0);
        System.out.println(v1);
        if (v0.size() != v1.size()) {
            return false;
        }
        for (int i = 0; i < v0.size(); i++) {
            if (v0.get(i) != v1.get(i)) {
                return false;
            }

        }
        return true;
    }

    public void dfs(TreeNode root, List<Integer> res) {
        if (root == null) {
            return;
        }

        dfs(root.left, res);
        if (root.left == null && root.right == null) {
            res.add(root.val);  //是叶子
            return;
        }
        dfs(root.right, res);


    }
}
